package com.leetcode.Offer;

public class JZ53 {
    public int search(int[] nums, int target) {

        int a = 0, b = nums.length - 1;
        while (a < b) {//找到第一个target，右指针不断向左移动
            int mid = a + (b - a) / 2;
            if (nums[mid] < target) {
                a = mid + 1;
            } else {
                b = mid;
            }
        }
        int count = 0;
        while (a < nums.length && nums[a++] == target) {
            count++;
        }
        return count;
    }
    //还可以使用遍历
}
